﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.ComponentModel.DataAnnotations;

namespace GestureService.Model
{
    [Serializable]
    public class measurement
    {
        public measurement() { }

        public long id { get; set; }

        private DateTime timeCreated { get; set; }

        public String timeCreatedString { get; set; }

        public DeviceType deviceType { get; set; }
        public int deviceTypeIndex { get; set; }

        public HandlingType handlingType { get; set; }
        public int handlingTypeIndex { get; set; }

        public float pathLength { get; set; }

        public GestureType gestureType { get; set; }
        public int gestureTypeIndex { get; set; }

        public GestureShapeType gestureShapeType { get; set; }
        public int gestureShapeTypeIndex { get; set; }

        public int checkpointNumber { get; set; }

        public Border beginCheckpointBorder { get; set; }

        public Border endCheckpointBorder { get; set; }

        public String timeLevelStartString { get; set; }

        private DateTime timeLevelStart { get; set; }

        public String timeSelectString { get; set; }

        private DateTime timeSelect { get; set; }

        public String timeActionEndString { get; set; }

        private DateTime timeActionEnd { get; set; }

        public double intervalLevelStartToSelect { get; set; }

        public double intervalSelectToActionEnd { get; set; }

        public bool isTestSuccesful { get; set; }

        public int pathColor { get; set; }

        public int beginCheckPointColor { get; set; }

        public int endCheckpointColor { get; set; }

        public int internalCheckpointColor { get; set; }

        public int backgroundColor { get; set; }

        public bool isBackgroundSolidColor { get; set; }

        public bool isPathVisible { get; set; }

        public bool isCheckpointIndexVisible { get; set; }

        public String beginPathLocationString { get; set; }

        private PointF beginPathLocation { get; set; }

        public String endPathLocationString { get; set; }

        private PointF endPathLocation { get; set; }

        public ScreenFieldType beginPathScreenField { get; set; }

        public ScreenFieldType endPathScreenField { get; set; }

        public double score { get; set; }

        // new

        public int dpi { get; set; }

        public String screenSizePxString { get; set; }

        private Point screenSizePx { get; set; }

        public double dragLength { get; set; }

        internal void parseAfterDatabaseLoad()
        {
            deviceType = (DeviceType)deviceTypeIndex;
            gestureShapeType = (GestureShapeType)gestureShapeTypeIndex;
            gestureType = (GestureType)gestureTypeIndex;
            handlingType = (HandlingType)handlingTypeIndex;
            beginCheckpointBorder.borderType = (BorderType)beginCheckpointBorder.borderTypeIndex;
            endCheckpointBorder.borderType = (BorderType)endCheckpointBorder.borderTypeIndex;

            timeCreated = DateTime.Parse(timeCreatedString);
            timeLevelStart = DateTime.Parse(timeLevelStartString);
            timeSelect = DateTime.Parse(timeSelectString);
            timeActionEnd = DateTime.Parse(timeActionEndString);
            beginPathLocation = parsePointF(beginPathLocationString);
            endPathLocation = parsePointF(endPathLocationString);
            screenSizePx = parsePoint(screenSizePxString);
        }

        internal void pareseAfterXmlLoad()
        {
            timeCreated = DateTime.Parse(timeCreatedString);
            timeLevelStart = DateTime.Parse(timeLevelStartString);
            timeSelect = DateTime.Parse(timeSelectString);
            timeActionEnd = DateTime.Parse(timeActionEndString);
            beginPathLocation = parsePointF(beginPathLocationString);
            endPathLocation = parsePointF(endPathLocationString);
            screenSizePx = parsePoint(screenSizePxString);


            deviceTypeIndex = (int)deviceType;
            gestureShapeTypeIndex = (int)gestureShapeTypeIndex;
            gestureTypeIndex = (int)gestureType;
            handlingTypeIndex = (int)handlingType;
            beginCheckpointBorder.borderTypeIndex = (int)beginCheckpointBorder.borderType;
            endCheckpointBorder.borderTypeIndex = (int)endCheckpointBorder.borderType;
        }


        public Point parsePoint(string s)
        {
            Point p = new Point();
            p.X = Int32.Parse(s.Split(',')[0]);
            p.Y = Int32.Parse(s.Split(',')[1]);
            return p;
        }

        public PointF parsePointF(string s)
        {
            PointF p = new PointF();
            p.X = float.Parse(s.Split(',')[0].Replace(".", ","));
            p.Y = float.Parse(s.Split(',')[1].Replace(".", ","));
            return p;
        }

    }
}